package com.wyf.armessage


import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.widget.SwipeRefreshLayout
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.wyf.armessage.adapter.HomeAdapter
import com.wyf.armessage.model.Message
import kotlinx.android.synthetic.main.fragment_home.*
import org.jetbrains.anko.listView
import org.jetbrains.anko.progressBar
import org.jetbrains.anko.support.v4.swipeRefreshLayout


class HomeFragment : Fragment() {


    var mContext:Context?=null
    var list = ArrayList<Message>()
    var adapter:HomeAdapter?=null


    fun newInstance(): HomeFragment {
        return  HomeFragment()
    }

    override fun onAttach(context: Context?) {
        super.onAttach(context)
        mContext = context
    }
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater!!.inflate(R.layout.fragment_home, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)



        initSwipeRefresh()
    }

     fun initSwipeRefresh(){

         index_swipyrefreshlayout.setOnRefreshListener {
             initData()
             initListView()
             index_swipyrefreshlayout.setRefreshing(false)
         }
     }

    fun initListView(){

         index_listview.adapter = adapter

     }

    fun initData(){

        var m=Message
        m.msg="11"
        list.add(m)
        list.add(m)
        list.add(m)
        list.add(m)
        list.add(m)
        list.add(m)
        adapter = HomeAdapter(mContext,list)

    }

}


